package com.spark.market.dal.repository.impl;

import com.spark.market.common.utils.AssertUtils;
import com.spark.market.dal.dao.SequenceInfoDoMapper;
import com.spark.market.dal.entity.SequenceInfoDo;
import com.spark.market.dal.repository.SequenceInfoRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class SequenceInfoRepositoryImpl implements SequenceInfoRepository {
    @Resource
    SequenceInfoDoMapper sequenceInfoDoMapper;

    @Override
    public SequenceInfoDo getSequenceByName(String name) {
        AssertUtils.isNotNull(name, "name is null");
        return sequenceInfoDoMapper.selectSequenceByName(name);
    }

    @Override
    public int updateSequenceValue(String name, Integer currentValue) {
        AssertUtils.isNotNull(name, "name is null");
        AssertUtils.isNotNull(currentValue, "currentValue is null");
        return sequenceInfoDoMapper.updateByNameAndCurrentValue(name, currentValue);
    }
}
